﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

public partial class MemberCenter : System.Web.UI.PageEx
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string strResult = string.Empty;
            if (!DalEx.DbUserDalEx.CheckUserLogin(UserType, UserId, ref strResult))
            {
                MessageBox(strResult, "UserLogin.aspx");
                return;
            }
            string strLink = "<li><a href=\"{0}\" class=\"{2}\">{1}</a></li>";
            StringBuilder sbMenuLinks = new StringBuilder();
            if (UserType == 1 && UserId > 0)
            {
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MemberCenter.aspx", "会员中心", "on" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "UserInfos.aspx", "我的资料", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "ModifyPwd.aspx", "修改密码", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MyBaoMing.aspx", "我的报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MyYiGongBaoMing.aspx", "义工报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MyHomeEventBaoMing.aspx", "家园活动报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "Logout.aspx", "退出系统", "" }));
            }
            else
            {
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "会员中心", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的资料", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "修改密码", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "义工报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "家园活动报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "退出系统", "" }));
            }
            litMenuLinks.Text = sbMenuLinks.ToString();

            DataBinds();
        }
    }
    private void DataBinds()
    {
        if (UserType == 1 && UserId > 0)
        {
            Model.DbUsers dbUser = DalEx.DbUserDalEx.Select(UserId);
            if (dbUser != null)
            {
                lblLastLoginIP.Text = dbUser.LastIP;
                lblLastLoginTime.Text = dbUser.LastLoginTime.ToString();
                lblLoginTime.Text = dbUser.LoginTimes.ToString() + "次";

                DataSet ds = DalEx.BaoMingEx.Select(" and UserId=" + dbUser.UserID);
                lblBaoMingCounts.Text = ds.Tables[0].Rows.Count.ToString();
                ds = DalEx.BaoMing2Ex.Select(" and UserId=" + dbUser.UserID);
                lblYiGongBaoMingCounts.Text = ds.Tables[0].Rows.Count.ToString();
                ds = DalEx.BaoMing3Ex.Select(" and UserId=" + dbUser.UserID);
                lblHomeEventsBaoMingCounts.Text = ds.Tables[0].Rows.Count.ToString();
            }
        }
    }
}
